﻿using ZeroBug.EasyFlow.Core;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Serialization;

namespace ZeroBug.EasyFlow.Motion
{
    public class Pdo : IMachineResource<IPdo>, IResourceVariable
    {
        public short CardNo { get; set; }
        public short BitNo { get; set; }
        public short Address { get; set; }
        public string Description { get; set; }
        public string Module { get; set; }
        [XmlIgnore]
        public IPdo PdoOperator { get; set; }
        public string OperatorName { get; set; }
        [XmlIgnore]
        public LogHelper Logger { get; set; }
        public Pdo()
        {

        }
        public Pdo(short cardNo, short bitNo, short address, string description, string moduleName)
            : this()
        {
            this.CardNo = cardNo;
            this.BitNo = bitNo;
            this.Address = address;
            this.Description = description;
            this.Module = moduleName;
        }
        public void SetData(int value)
        {
            PdoOperator.WritePdoData((ushort)CardNo, (ushort)BitNo, (ushort)Address, 2, value);
        }
        public int ReadData()
        {
            int val = 0;
            PdoOperator.ReadPdoData((ushort)CardNo, (ushort)BitNo, (ushort)Address, 2, ref val);
            return val;
        }

        public void SetOperator(IPdo machineOperator)
        {
            this.PdoOperator = machineOperator;
        }
    }
}
